package com.huawei.hwclouds.lubanops.demo.product.biz.service;

import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;

import com.huawei.hwclouds.lubanops.demo.common.biz.PageList;
import com.huawei.hwclouds.lubanops.demo.common.json.JsonUtil;
import com.huawei.hwclouds.lubanops.demo.product.biz.BizAbstractJUnitTest;
import com.huawei.hwclouds.lubanops.demo.product.biz.model.MerchandiseModel;
import com.huawei.hwclouds.lubanops.demo.product.biz.model.MerchandiseStockModel;
import com.huawei.hwclouds.lubanops.demo.product.biz.param.MerchandiseParam;

/**
 * @author y00438022
 * @since 2020/8/17
 **/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MerchandiseServiceTest extends BizAbstractJUnitTest {

//    private static final String ak = System.currentTimeMillis() / 1000 + "";

    private static int id;

    @Autowired
    private MerchandiseService merchandiseService;

    @Test
    public void aTestCreate() {
        MerchandiseModel model = new MerchandiseModel();
        model.setIntro("肥皂");
        model.setName("中华肥皂");
        model.setStandardPrice(12.5);
        merchandiseService.create(model);
        Assert.assertTrue(model.getId() > 0);
    }

    @Test
    public void testPageQuery() {
        MerchandiseParam param = new MerchandiseParam();
        param.setPageNumber(1);
        param.setPageSize(5);
        PageList<MerchandiseModel> result = merchandiseService.pageQuery(param);
        Assert.assertTrue(result.getDataList().size() > 0);
        System.out.println("rows queried:" + result.getDataList().size());
    }

    @Test
    public void selectById() {
        MerchandiseParam param = new MerchandiseParam();
        MerchandiseModel model = merchandiseService.retrieveById(1);

        Assert.assertTrue(model.getName() != null);
    }

    @Test
    public void test() {
//        MerchandiseStockModel param = new MerchandiseStockModel();
//        param.setMerchandiseId(1);
//        param.setCount(222222);
//        String s = JsonUtil.toJSONString(param);
//        merchandiseService.reduceRepertory(param);

    }

}
